/* ***********************
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is briefAuthorsEmail.js module.
 *
 * The Initial Developer of the Original Code is Rob Gerns.
 *
 * Portions created by the Initial Developer are Copyright (C) 2011
 * the Initial Developer. All Rights Reserved.
 *
 **************************/
function getBriefAuthorsEmail(objXmlDocument) {	
    /*************************************************
    * Function Name: getBriefAuthorsEmail
    * 
    * Purpose: Check to see if there are any authors' e-mail addresses
    * defined in the 'brief' section of the Oister file.  If 
    * so, retrieve the value of each.
    **************************************************/	
    var objAuthors = objXmlDocument.getElementsByTagName("authors")[0];
    var objAuthorEmail = "";
    var objAuthorName = "";
    var intAuthorNameCount = "";
    var intAuthorEmailCount = "";
    var strAuthorEmail = "";
    var intCounter = 0;
    var intCounterTwo = 0;
    
    if (objAuthors !== undefined) {
      objAuthorEmail = objAuthors.getElementsByTagName("authorEmail");
      objAuthorName = objAuthors.getElementsByTagname("authorName");
      intAuthorNameCount = objAuthorName.length;
      intAuthorEmailCount = objAuthorsEmail.length;      
    }
    if (intAuthorEmailCount !== "" && intAuthorEmailCount > 0) {
        //Weird counter because authorEmail and authorName are optional.
        intCounter = (intAuthorNameCount + intAuthorEmailCount) * 2;
	 	 
        for (intCounterThree = 0; intCounterThree < intCounter; intCounter++){
            //The authorEmail node should be a child of the "authors" node.
            objAuthorEmailNode = objAuthors.childNodes[intCounter + 1]; 
		
		        //Make sure the child node is actually an authorEmail node.
            if (objAuthorEmailNode.nodeName === "authorEmail") { 
                strAuthorEmail = objAuthorEmailNode.firstChild.nodeValue;
                //intCounter is incremented by 2, so subtract 1 before passing.
                intCounterTwo = intCounter - 1;
                //Call the writeAuthors function.
                writeBriefAuthorsEmail(strAuthorEmail, intCounterTwo);
            }
        }
    }	
}
function writeBriefAuthorsEmail(strAuthorEmail, intCounterTwo) {
    /*************************************************
    * Function Name: writeBriefAuthorsEmail
    * 
    * Purpose: Write the appropriate HTML to display the 
    * authorEmail value.
    **************************************************/ 
    var objDivAuthorEmail = "";
    var objDivAuthorEmailId = "";
    //intCounterTwo was to prevent ID from being authors0, authors2, etc.
    var strAuthorNameId = "authors" + intCounterTwo;
 
    objDivAuthorEmail = document.createElement("div");
    document.getElementById(strAuthorNameId).appendChild(objDivAuthorEmail);
    objDivAuthorEmailId = objDivAuthorEmail.id = "authorEmail" + intCounterTwo;
    objDivAuthorEmail.className = "authorEmail";
    objDivAuthorEmail.innerHTML = strAuthorEmail;
}